﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using StoryTeller.Domain;
using StoryTeller.Repository;
using System.Collections.Generic;

namespace StoryTeller.UnitTest.Repository
{
    [TestClass]
    public class UserRepositoryUnitTest
    {
        public UserRepository repository { get { return new UserRepository(); } }

        public User user
        {
            get
            {
                return new User()
                {
                    Name = "name...",
                    UserIdentity = DateTime.Now.Ticks.ToString()
                };
            }
        }

        [TestMethod]
        public void Insert()
        {
            repository.Insert(user);
        }

        [TestMethod]
        public void Update()
        {
            User u = repository.Select().Last();
            u.Name += " = updated" + DateTime.Now.ToShortDateString();

            repository.Update(u);
        }

        [TestMethod]
        public void Delete()
        {
            User u = repository.Select().Last();

            repository.Delete(u.Id);
        }

        [TestMethod]
        public void Select()
        {
            ICollection<User> coll = repository.Select();

            Assert.IsNotNull(coll);
        }

        [TestMethod]
        public void SelectById()
        {
            User u = repository.Select().Last();
            
            Assert.IsNotNull(u);
        }
    }
}
